using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using StudentVideo.Common.Attributes;
using StudentVideo.Common.Constants;
using StudentVideo.Common.Exceptions;
using StudentVideo.Data;
using StudentVideo.Shared.Dtos.Major;
using StudentVideo.Shared.Enums;

namespace StudentVideo.Controllers;

[ApiController]
[Route("api/[controller]/[action]")]
[RoleAuthorize(RoleEnum.Admin)]
public class MajorControllers(AppDbContext context): ControllerBase {
   private readonly AppDbContext _context = context;

   [HttpPost]
   public async Task Create([FromBody] MajorCreateRequest data) {
      var exists = await _context.Majors.AnyAsync(e => e.Code == data.Code);

      if (exists)
         throw new HttpException(HttpErrorMessage.MAJOR_EXIST);
   }

}
